package logic

import (
	"context"
	"taobao-merchandise/models/mysql"

	"taobao-merchandise/taobaorpc/internal/svc"
	"taobao-merchandise/taobaorpc/taobaorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsListLogic) GoodsList(in *taobaorpc.GoodsListRequest) (*taobaorpc.GoodsListResponse, error) {
	// todo: add your logic here and delete this line

	var goods mysql.Goods
	var lists []*taobaorpc.GoodsList

	var err error
	if lists, err = goods.GoodsList(mysql.DB, in, lists); err != nil {
		return nil, err
	}

	return &taobaorpc.GoodsListResponse{
		List: lists,
	}, nil
}
